package testing.module;

import java.awt.AlphaComposite;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Properties;

import javax.imageio.ImageIO;

import utilities.display.imgs.DrawImage;
import utilities.module.Module;

public class IntroScreen extends Module
{

	/**
	 * 
	 */
	private static final long serialVersionUID = -3327245925555363246L;
	
	protected BufferedImage bgImg;
	protected BufferedImage cliffImg;
	//protected BufferedImage subtitleImg;
	//protected BufferedImage titleTag;
	
	protected DrawImage titleTag;
	protected DrawImage subtitleImg;
	protected DrawImage moonImg;

	protected ArrayList<DrawImage> buttons;
	protected ArrayList<DrawImage> clouds;
	
	protected double buttonScale = .6;
	protected int buttonXStart = 190;
	protected int buttonYStart = 250;
	protected int buttonDX = 0;
	protected int buttonDY = 40;
	
	public IntroScreen() throws IOException
	{
		bgImg = ImageIO.read(new File("resources//imgs//title//background.png"));
		cliffImg = ImageIO.read(new File("resources//imgs//title//cliff.png"));
		//subtitleImg = ImageIO.read(new File("resources//imgs//title//buttons//subtitle.png"));
		
		BufferedImage title = ImageIO.read(new File("resources//imgs//title//wingslogocropped.png"));
		BufferedImage subtitle = ImageIO.read(new File("resources//imgs//title//subtitle.png"));
		BufferedImage moon = ImageIO.read(new File("resources//imgs//title//moons.png"));

		titleTag = new DrawImage(title, null, 0.7, 10, 10);
		subtitleImg = new DrawImage(subtitle, null, 0.5, 22, 60);
		moonImg = new DrawImage(moon, AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .45f), 1, 150, 30);

		// Get button images
		buttons = new ArrayList<DrawImage>();
		
		// Practice Choice
		buttons.add(new DrawImage(ImageIO.read(new File("resources//imgs//title//buttons//PRACTICE.png")), null, buttonScale, buttonXStart + buttonDX, buttonYStart));
		
		// Local Choice
		buttons.add(new DrawImage(ImageIO.read(new File("resources//imgs//title//buttons//LOCAL.png")), null, buttonScale, buttonXStart + buttonDX, buttonYStart + buttonDY));
		
		// Online Choice
		buttons.add(new DrawImage(ImageIO.read(new File("resources//imgs//title//buttons//ONLINE.png")), null, buttonScale, buttonXStart + buttonDX, buttonYStart + buttonDY * 2));
		
		// Credits Choice
		buttons.add(new DrawImage(ImageIO.read(new File("resources//imgs//title//buttons//CREDITS.png")), null, buttonScale, buttonXStart + buttonDX, buttonYStart + buttonDY * 3));

		clouds = new ArrayList<DrawImage>();
		
		// Load up clouds
		//for(int i = 1; i <= 4; i++)
		//for(int i = 3; i <= 3; i++)
		//{
			//BufferedImage cloud = ImageIO.read(new File("resources//imgs//title//cloud" + i + ".png"));
			//clouds.add(new DrawImage(cloud, AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .55f), 1, 20* i, 20));
		//}
		BufferedImage cloud1 = ImageIO.read(new File("resources//imgs//title//cloud1.png"));
		BufferedImage cloud2 = ImageIO.read(new File("resources//imgs//title//cloud2.png"));		
		BufferedImage cloud3 = ImageIO.read(new File("resources//imgs//title//cloud3.png"));
		BufferedImage cloud4 = ImageIO.read(new File("resources//imgs//title//cloud4.png"));
	}

	public void drawMe(Graphics g)
	{
		Graphics2D g2 = (Graphics2D)g;
		
		// Draw background scenery
		
		// Background sky
		g2.drawImage(bgImg, 0, 0, bgImg.getWidth(), bgImg.getHeight(), null);
		
		// Moon
		moonImg.drawMe(g2);
		
		// Clouds
		for(DrawImage img : clouds)
		{
			if(img != null) img.drawMe(g2);
		}
		
		// Cliff
		g2.drawImage(cliffImg, 0, 0, cliffImg.getWidth(), cliffImg.getHeight(), null);
		
		// Draw UI
		titleTag.drawMe(g2);
		subtitleImg.drawMe(g2);
		
		// Draw buttons
		for(DrawImage button : buttons)
		{
			if(button != null) button.drawMe(g2);
		}
	}

	public void update(Properties globals) 
	{
		for(DrawImage img : clouds)
		{
			if(img != null) img.translate(-1, 0);
		}
	}
}
